package com.usian.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.admin.mapper.SensitiveMapper;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SensitiveServiceImpl extends BaseServiceImpl<SensitiveMapper, AdSensitive>  {
    public ResponseResult list(SensitiveDto dto) {
        if (dto == null)return paramError;
        return getPageData(dto, Wrappers.<AdSensitive>lambdaQuery().like(StringUtils.isNotBlank(dto.getName()),AdSensitive::getSensitives,dto.getName()));
    }

    public ResponseResult saves(AdSensitive adSensitive) {
        if (adSensitive == null)return paramError;
        adSensitive.setCreatedTime(new Date());
        return success(save(adSensitive));
    }

    public ResponseResult update(AdSensitive adSensitive) {
        if (adSensitive == null)return paramError;
        return success(updateById(adSensitive));
    }

    public ResponseResult deleteById(Integer id) {
        if (id == null)return paramError;
        return success(removeById(id));
    }
}
